package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendPunchCalibrationAddDTO;
import org.jsola.hr.dto.AttendPunchCalibrationUpdateDTO;
import org.jsola.hr.entity.AttendPunchCalibrationDO;
import org.jsola.hr.query.AttendPunchCalibrationQuery;
import org.jsola.hr.service.IAttendPunchCalibrationService;
import org.jsola.hr.vo.AttendPunchCalibrationVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 考勤打卡校准记录表
 *
 * @author zhr
 */
@Component
public class AttendPunchCalibrationTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendPunchCalibrationService attendPunchCalibrationService;

    /**
     * 生成add测试数据
     * @return AttendPunchCalibrationAddDTO
     */
    public AttendPunchCalibrationAddDTO getAttendPunchCalibrationAddDTO(){
        AttendPunchCalibrationAddDTO attendPunchCalibrationAddDTO = new AttendPunchCalibrationAddDTO();
        attendPunchCalibrationAddDTO.setPunchRecordId(getRandomValue("varchar",32));
        attendPunchCalibrationAddDTO.setRemark(getRandomValue("varchar",255));
        attendPunchCalibrationAddDTO.setHisPunchStatus(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendPunchCalibrationAddDTO.setHisPunchTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        attendPunchCalibrationAddDTO.setCalibrationMethod(getRandomValue("varchar",32));
        return attendPunchCalibrationAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendPunchCalibrationUpdateDTO
     */
    public AttendPunchCalibrationUpdateDTO getAttendPunchCalibrationUpdateDTO(AttendPunchCalibrationVO attendPunchCalibrationVO){
        return attendPunchCalibrationService.selectDOById(attendPunchCalibrationVO.getId(), SITE_ID).to(AttendPunchCalibrationUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendPunchCalibrationQuery
     */
    public AttendPunchCalibrationQuery getAttendPunchCalibrationQuery() {
        AttendPunchCalibrationQuery attendPunchCalibrationQuery = new AttendPunchCalibrationQuery();
        List<AttendPunchCalibrationDO> attendPunchCalibrationDOList = attendPunchCalibrationService.list(new AttendPunchCalibrationDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendPunchCalibrationDOList)) {
            AttendPunchCalibrationDO attendPunchCalibrationDO = attendPunchCalibrationDOList.get(0);
            attendPunchCalibrationQuery = attendPunchCalibrationDO.to(AttendPunchCalibrationQuery.class);
            if (attendPunchCalibrationDO.getHisPunchTime() != null) {
                attendPunchCalibrationQuery.setHisPunchTimeStart(DateKit.getBeforeDay(attendPunchCalibrationDO.getHisPunchTime(),-1));
                attendPunchCalibrationQuery.setHisPunchTimeEnd(DateKit.getBeforeDay(attendPunchCalibrationDO.getHisPunchTime(),1));
            }
        }
        return attendPunchCalibrationQuery;
    }

    /**
     * 保存示例
     * @return AttendPunchCalibrationVO
     */
    public AttendPunchCalibrationVO saveAttendPunchCalibrationExample(){
        AttendPunchCalibrationAddDTO addDTO = this.getAttendPunchCalibrationAddDTO();
        AttendPunchCalibrationVO attendPunchCalibrationVO = attendPunchCalibrationService.save(addDTO,buildTokenUser());
        return attendPunchCalibrationVO;
    }


}

